/*
 * Copyright (C) 2004, Velocityme Partnership
 * Contactable.java
 *
 * Created on 14 January 2004, 08:03
 */

package com.velocityme.entity;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import com.velocityme.interfaces.*;
import com.velocityme.valueobjects.ContactableValue;
import java.util.Collection;
import java.util.Iterator;

/**
 *
 * @author  Robert Crida Work
 * @ejb.bean
 *           type="CMP"
 *           cmp-version="2.x"
 *           name="Contactable"
 *           jndi-name="ejb/Contactable"
 *           view-type="local"
 * @ejb.transaction type="Required"
 *
 * @ejb.value-object match="*"
 *
 * @ejb.persistence table-name="contactable"
 *
 * @ejb.util generate="physical"
 *
 * @ejb.finder signature="java.util.Collection findAll()"
 *              query="SELECT OBJECT(o) FROM Contactable o WHERE o.nodeLocal.dBObjectLocal.isDeleted = FALSE"
 *
 * @jboss.persistence create-table="true"
 *                    remove-table="false"
 */
public abstract class ContactableBean implements EntityBean {
    
    /**
    * Context set by container
    */
    private javax.ejb.EntityContext m_entityContext;

    public void setEntityContext(javax.ejb.EntityContext entityContext) {
        m_entityContext = entityContext;
    }

    public void unsetEntityContext() {
        m_entityContext = null;
    }
  
    /** @ejb.create-method */
    public com.velocityme.interfaces.ContactablePK ejbCreate(com.velocityme.interfaces.NodeLocal p_nodeLocal,
                                                             com.velocityme.valueobjects.ContactableValue p_value) throws CreateException {
        setContactableId(p_nodeLocal.getNodeId());
        // EJB 2.0 spec says return null for CMP ejbCreate methods.
        return null;
    }

    public void ejbPostCreate(com.velocityme.interfaces.NodeLocal p_nodeLocal,
                              com.velocityme.valueobjects.ContactableValue p_value) throws CreateException {
        // CMR relations must be set in ejbPostCreate
        setContactableValue(p_value);
        setNodeLocal(p_nodeLocal);
    }
    
    /**
     *  This gets a local object from a remote object.
     *  @ejb.interface-method view-type="remote"
     */
    public com.velocityme.interfaces.ContactableLocal getLocal() {
        return (ContactableLocal)m_entityContext.getEJBLocalObject();
    }
    
    /** @ejb.interface-method view-type="local" */
    public abstract com.velocityme.valueobjects.ContactableValue getContactableValue();
    /** @ejb.interface-method view-type="local" */
    public abstract void setContactableValue(com.velocityme.valueobjects.ContactableValue p_value);

    //=======================================================================
    //
    //                   ATTRIBUTES
    //
    //=======================================================================
      
    /**
     * @ejb.persistence column-name="contactableId"
     * @ejb.interface-method view-type="local"
     * @ejb.pk-field 
     */
    public abstract java.lang.Integer getContactableId();
    /** @ejb.interface-method view-type="local" */
    public abstract void setContactableId(java.lang.Integer contactableId);

    /**
     * @ejb.persistence column-name="type"
     * @ejb.interface-method view-type="local"
     */
    public abstract java.lang.String getType();
    /** @ejb.interface-method view-type="local" */
    public abstract void setType(java.lang.String description);
    
    //=======================================================================
    //
    //                   RELATIONSHIPS
    //
    //=======================================================================
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Contactable-Node"
     *               role-name="Contactable-has-a-Node"
     * @jboss.relation fk-column="nodeIdFk"
     *                 related-pk-field="nodeId"
     * @ejb.value-object match="*" 
     *                   aggregate="com.velocityme.valueobjects.NodeValue"
     *                   aggregate-name="NodeValue"
     */
    public abstract com.velocityme.interfaces.NodeLocal getNodeLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setNodeLocal(com.velocityme.interfaces.NodeLocal nodeLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Organisation-Contactable"
     *               role-name="Contactable-may-have-an-Organisation"
     */
    public abstract com.velocityme.interfaces.OrganisationLocal getOrganisationLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setOrganisationLocal(com.velocityme.interfaces.OrganisationLocal organisaionLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Department-Contactable"
     *               role-name="Contactable-may-have-a-Department"
     */
    public abstract com.velocityme.interfaces.DepartmentLocal getDepartmentLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setDepartmentLocal(com.velocityme.interfaces.DepartmentLocal departmentLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Person-Contactable"
     *               role-name="Contactable-may-have-a-Person"
     */
    public abstract com.velocityme.interfaces.PersonLocal getPersonLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setPersonLocal(com.velocityme.interfaces.PersonLocal personLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="ContactDetail-Contactable"
     *               role-name="Contactable-has-many-ContactDetails"
     *               target-ejb="ContactDetail"
     *               target-role-name="ContactDetail-has-a-Contactable"
     *               target-multiple="no"
     * @jboss.target-relation fk-column="contactableIdFk"
     *                        related-pk-field="contactableId"
     * @ejb.value-object match="*" 
     *                   compose="com.velocityme.valueobjects.ContactDetailValue"
     *                   compose-name="ContactDetailValue"
     *                   members="com.velocityme.interfaces.ContactDetailLocal"
     *                   members-name="ContactDetailLocal"
     *                   relation="external"
     *                   type="Collection"
     */
    public abstract java.util.Collection getContactDetailsLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setContactDetailsLocal(java.util.Collection contactDetailsLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Task-Responsible-Contactable"
     *               role-name="Contactable-may-be-responsible-for-many-Tasks"
     * @jboss.relation fk-column="contactableId"
     *                 related-pk-field="taskId"
     * @jboss.relation-table table-name="responsiblecontactables"
     *                       create-table="true"
     *                       remove-table="false"
     */
    public abstract java.util.Collection getResponsibleTasksLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setResponsibleTasksLocal(java.util.Collection tasks);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Task-Interested-Contactable"
     *               role-name="Contactable-may-be-interested-in-many-Tasks"
     * @jboss.relation fk-column="contactableId"
     *                 related-pk-field="taskId"
     * @jboss.relation-table table-name="interestedcontactables"
     *                       create-table="true"
     *                       remove-table="false"
     */
    public abstract java.util.Collection getInterestedTasksLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setInterestedTasksLocal(java.util.Collection tasks);
    
    //=======================================================================
    //
    //                   MANAGEMENT METHODS
    //
    //=======================================================================
    
    /** 
     * @ejb.interface-method view-type="local"
     */
    public java.lang.String getName() {
        return getNodeLocal().getName();
    }
    
}
